package org.example.rubbish.mapper;


import org.apache.ibatis.annotations.*;
import org.example.rubbish.entity.InventoryIn;
import org.example.rubbish.entity.InventoryOut;

import java.util.Date;
import java.util.List;

@Mapper
public interface InventoryMapper {
    // 入库记录
    @Insert("INSERT INTO inventory_in(station_id, user_id, weight, points, image_url, video_url) " +
            "VALUES(#{stationId}, #{userId}, #{weight}, #{points}, #{imageUrl}, #{videoUrl})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insertInventoryIn(InventoryIn inventoryIn);

    @Select("SELECT * FROM inventory_in WHERE id=#{id}")
    InventoryIn selectInventoryInById(Long id);

    @Select("SELECT * FROM inventory_in WHERE station_id=#{stationId}")
    List<InventoryIn> selectInventoryInByStationId(Long stationId);

    @Select("SELECT * FROM inventory_in WHERE user_id=#{userId}")
    List<InventoryIn> selectInventoryInByUserId(Long userId);

    @Select("SELECT * FROM inventory_in WHERE create_time BETWEEN #{startTime} AND #{endTime}")
    List<InventoryIn> selectInventoryInByTimeRange(Date startTime, Date endTime);

    // 出库记录
    @Insert("INSERT INTO inventory_out(station_id, weight, operator) " +
            "VALUES(#{stationId}, #{weight}, #{operator})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insertInventoryOut(InventoryOut inventoryOut);

    @Select("SELECT * FROM inventory_out WHERE id=#{id}")
    InventoryOut selectInventoryOutById(Long id);

    @Select("SELECT * FROM inventory_out WHERE station_id=#{stationId}")
    List<InventoryOut> selectInventoryOutByStationId(Long stationId);

    @Select("SELECT * FROM inventory_out WHERE create_time BETWEEN #{startTime} AND #{endTime}")
    List<InventoryOut> selectInventoryOutByTimeRange(Date startTime, Date endTime);
}
